<script>
  let activeEffect;
  class Dep {
    constructor(value) {
      this.subscribers = new Set();
      this._value = value
    }
    get value() {
      this.depend()
      return this._value
    }
    set value(newvalue) {
      this._value = newvalue
      this.notify()
    }
    depend() {
      if (activeEffect) {
        this.subscribers.add(activeEffect)
      }
    }
    notify() {
      this.subscribers.forEach(effect => {
        effect()
      })
    }
  }

  function watchEffect(effect) {
    activeEffect = effect;
    effect();
    activeEffect = null;
  }

  const dep = new Dep('hello')

  watchEffect(() => {
    console.log('effect run')
  }) // effect run

  dep.value = 'changed'
</script>